<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="utils/index.js"></script>
    <style>
        #app{
            padding-top: 20px;
            padding-left: 200px;
        }
        .title{
            font-size: 20px;
        }
        .container{
            overflow: hidden;
            margin-top: 10px;
        }
        .title,.num{
            float: left;
        }
        .num{
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 1px solid #666;
            text-align: center;
            margin-left: 60px;
            line-height: 20px;
        }
        .check{
            width: 18px;
            height: 18px;
            font-size: 18px;
        }
    </style>
</head>
<body>
    <div id="app">
        <input type="text" @keyup.enter="handleEnter" v-model.trim="keyword">
        <div class="container">
            <div class="title">正在进行</div>
            <div class="num">{{doingLists.length}}</div>
        </div>
            <div v-for="item of doingLists" :key="item.name">
                <input class="check" type="checkbox" 
                v-model="item.state">{{item.name}}
                <button @click="onDelete(item.name)">删除</button>
            </div>
        
        <div class="container">
            <div class="title">已经完成</div>
            <div class="num">{{finishedLists.length}}</div>
        </div>
            <div v-for="item of finishedLists" :key="item.name">
                <input class="check" type="checkbox" 
                v-model="item.state">{{item.name}}
                <button @click="onDelete(item.name)">删除</button>
            </div>
        
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                keyword:"",
                lists:[]
            },
            methods: {
                handleEnter(){
                    var value = this.keyword
                    var res = this.lists.every(item=>item.name!=value)
                    if(value && res){
                        this.lists.push({
                            name:value,
                            state:false
                        })
                    }
                },
                onDelete(name){
                    var arr = this.lists.filter(item=>item.name!=name)
                    this.lists = arr
                }
            },
            mounted() {
                var skill = getStorage("skill")
                if(skill){
                    this.lists = skill
                }else{
                    setStorage("skill",[])
                }
            },
            computed:{
                finishedLists(){
                    return this.lists.filter(item=>item.state==true)
                },
                doingLists(){
                    return this.lists.filter(item=>item.state==false)
                }
            },
            watch:{
                finishedLists:function(){
                    setStorage("skill",this.lists)
                },
                doingLists:function(){
                    setStorage("skill",this.lists)
                }
            }
        })
    </script>
</body>
</html>